﻿#region using...
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;
#endregion

namespace Infusion.Silverlight.Controls
{
    #region : Clipboard :
    public class Clipboard
    {
        #region Methods...
        #region SetText
        /// <summary>
        /// Sets the text on the clipboard.
        /// NOTE: Only works with Internet Explorer.
        /// </summary>
        /// <param name="text">Text to be placed on the clipboard.</param>
        /// <returns>Whether or not setting the text was successful.</returns>
        public static bool SetText(string text)
        {
            bool success = false;

            var clipboardData = (ScriptObject)HtmlPage.Window.GetProperty("clipboardData");
            if (clipboardData != null)
            {
                success = (bool)clipboardData.Invoke("setData", "text", text);
            }

            return success;
        }
        #endregion

        #region GetText
        /// <summary>
        /// Gets the text currently on the clipboard.
        /// NOTE: Only works with Internet Explorer.
        /// </summary>
        /// <returns>The text from the clipboard.</returns>
        public static string GetText()
        {
            string text = string.Empty;

            var clipboardData = (ScriptObject)HtmlPage.Window.GetProperty("clipboardData");
            if (clipboardData != null)
            {
                text = (string)clipboardData.Invoke("getData", "text");
            }

            return text;
        }
        #endregion
        #endregion
    }
    #endregion
}